package Demo5;

import java.util.concurrent.*;

public class Main21 {
    public static void main(String[] args) throws InterruptedException {
       ExecutorService executors=Executors.newFixedThreadPool(10);
       CountDownLatch latch=new CountDownLatch(10);
        for (int i = 0; i <10 ; i++) {
            int id=i;
            executors.submit(()->{
                System.out.println("开始执行任务"+id);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("结束执行任务"+id);
                latch.countDown();
            });

        }
        latch.await();
        System.out.println("所有任务全部执行完毕");
    }
}
